<?php
	//No direct access
	defined('_JEXEC') or die('Restricted access');
	$priceformat = OwnserviceHelper::getParams('price_format', '#,###.##');
	$dateformat  = OwnserviceHelper::getParams('date_format', '%d/%m/%Y'); 
?>
<div id="ownservices">
	<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
	<div id="mainownservice">
		<h3><?php echo $this->params->get('page_title'); ?></h3>
		<hr />
		<table width="100%" cellspacing="1">
		<?php
			foreach($this->rows as $row):
		?>
		<tr>
			<td><span style="background-color: yellow; border: 1px solid; padding: 5px 0px; clear: both; font-weight: bold;"><?php echo $row['transferrer']->name; ?></span></td>
		</tr>
		<tr>
			<td>
			<table width="100%" cellspacing="1" class="adminlist">
				<tr>
					<th align="center"><?php echo JText::_('NUM'); ?></th>
					<th align="center"><?php echo JText::_('OWNSERVICE_RECEIVER_NO'); ?></th>
					<th align="center"><?php echo JText::_('OWNSERVICE_ACCOUNT_NO'); ?></th>
					<th align="center" width="5%"><?php echo JText::_('OWNSERVICE_ACCOUNT_NAME'); ?></th>
					<th align="center"><?php echo JText::_('OWNSERVICE_BANK_NAME'); ?></th>
					<th align="center"><?php echo JText::_('OWNSERVICE_AMOUNT_TRANSFER'); ?><br />(AUD)</th>
					<th align="center"><?php echo JText::_('OWNSERVICE_RATE'); ?></td>
					<th align="center"><?php echo JText::_('OWNSERVICE_TOTAL_EXCHANGE'); ?></th>
					<th align="center"><?php echo JText::_('OWNSERVICE_DISTRIBUTED_DATE'); ?></th>
				</tr>
				<?php 
					$k=0; 
					$i=1; 
					foreach($row['transactions'] as $transaction):
					$link	= JRoute::_('index.php?option=com_ownservice&controller=transaction&task=detail&id='.$transaction->id);
				?>
				<tr class="<?php echo "row$k"; ?>">
					<td align="center"><?php echo $i; ?></td>
					<td><a href="<?php echo $link; ?>"><?php echo $transaction->invoice; ?></a></td>
					<td><?php echo OwnserviceHelper::accountFormat($transaction->account); ?></td>
					<td><?php echo $transaction->account_name; ?>
					<td>
						<?php if($transaction->bank_name=='other'): ?>
							<?php echo $transaction->bank_other; ?>
						<?php else: ?>
							<?php echo $transaction->bank_name; ?>
						<?php endif; ?>
					</td>
					<td align="center"><?php echo OwnserviceHelper::moneyFormat($priceformat,$transaction->amount); ?></td>
					<td align="right" nowrap="nowrap">
					<?php
						$color = '';
						if($transaction->extrarate > 0.00 ) {
							$color = 'red';
						} else if($transaction->extrarate < 0.00) {
							$color = 'green';
						}
					?>
				<?php if(!$transaction->iscore): ?>
				<div style="border-bottom: 1px solid;">
					<?php echo OwnserviceHelper::moneyFormat($priceformat,$transaction->rate_th); ?> THB
				</div>
				<?php endif; ?>
				<div>
					<span class ="<?php echo $color; ?>"><?php echo OwnserviceHelper::moneyFormat($priceformat,$transaction->rate+$transaction->extrarate); ?></span>
					<?php echo $transaction->rate_code; ?> 
				</div>
				</td>
				<td align="right" nowrap="nowrap">
				<?php
					/*$color = '';
					$total = 0;
					if($transaction->extratotal > 0.00 ) {
						$color = 'red';
						$total = $transaction->extratotal;
					} else {
						$total = $transaction->amount * ($transaction->rate+$transaction->extrarate);
					}*/
				?>
				<?php if(!$transaction->iscore): ?>
					<div style="border-bottom: 1px solid;">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,$transaction->total_th); ?> THB
					</div>
				<?php endif; ?>
					<div>
						<span class="<?php echo ($transaction->extratotal > 0.00?'red':''); ?>">
							<?php 
								if($transaction->extratotal > 0.00) {
									echo OwnserviceHelper::moneyFormat($priceformat, $transaction->extratotal);
								} else {
									echo OwnserviceHelper::moneyFormat($priceformat,( ($transaction->amount * ($transaction->rate+$transaction->extrarate)) - ($transaction->bankfee+$transaction->extrabfee))); 
								}
							?>
						</span> <?php echo $transaction->rate_code; ?>
					</div>
				</td>
				<td align="center">
					<?php echo JHTML::_('date', $transaction->requested_date, $dateformat); ?>
				</td>
				</tr>
				<?php  $k = 1 - $k; $i++;endforeach; ?>
			</table>
			</td>
		</tr>
		<?php
			endforeach;
		?>
		</table>
	</div>
</div>